@extends('system.frame_layout')
<?php $parent_menu = "个人信息"; $menu_selected = "我的信息修改";?>

@section('content')
    <div id="content-panel">
        <div class="row">
            <div class="col-xs-12">
                <div class="portlet light bordered">
                    <div class="portlet-title">
                        <div class="caption">
                            <i class="icon-social-dribbble font-dark hide"></i>
                            <span class="caption-subject font-dark bold">我的信息修改 My Information Changes</span>
                        </div>
                    </div>
                    <div class="portlet-body">
                        <div class="form-group">
                            <form role="form"
                                  action="{{route('sys.information.save',['id'=>(isset($user)?$user->id:0)])}}"
                                  method="post" id="myInfo">
                                <div class="form-body">
                                    @if( $user->first == 0)
                                        <div class="alert alert-success">
                                            <strong>修改须知：</strong> 用户信息只能修改一次请慎重填写！
                                        </div>
                                    @elseif($user->first == 1)
                                        <div class="alert alert-danger">
                                            <strong>警告：</strong> 你已修改过一次资料，已不可再次修改，请联系管理员！
                                        </div>
                                    @endif
                                    {{ csrf_field() }}
                                    <div class="row input-row">
                                        <label class="col-xs-12 title" for="exampleInputPassword1">
                                            绑定电子邮箱 - Bind Email
                                        </label>
                                        <div class="col-md-4 col-xs-12">
                                            <div class="input-group">
                                                    <span class="input-group-addon">
                                                        <i class="iconfont icon-bixuan-copy font-red"></i>
                                                    </span>
                                                <input type="text" class="form-control" id="email" name="email"
                                                       value="{{isset($user->email)?$user->email:''}}"
                                                       placeholder="your email @ 163.com">
                                            </div>
                                        </div>
                                        <div class="col-xs-12 col-md-6">
                                            <label class="label-intro" for="realname"></label>
                                        </div>
                                    </div>

                                    <div class="row input-row">
                                        <label class="col-xs-12 title" for="exampleInputPassword1">
                                            真实姓名 - Name
                                        </label>
                                        <div class="col-md-4 col-xs-12">
                                            <div class="input-group">
                                                    <span class="input-group-addon">
                                                        <i class="iconfont icon-bixuan-copy font-red"></i>
                                                    </span>
                                                <input type="text" class="form-control" id="realname" name="realname"
                                                       value="{{isset($user->realname)?$user->realname:''}}"
                                                       placeholder="请如实填写">
                                            </div>
                                        </div>
                                        <div class="col-xs-12 col-md-6">
                                            <label class="label-intro" for="realname"></label>
                                        </div>
                                    </div>

                                    <div class="row input-row">
                                        <label class="col-xs-12 title" for="exampleInputPassword1">
                                            联系方式 - Telephone Number
                                        </label>
                                        <div class="col-md-4 col-xs-12">
                                            <div class="input-group">
                                                    <span class="input-group-addon">
                                                        <i class="iconfont icon-bixuan-copy font-red"></i>
                                                    </span>
                                                <input type="text" class="form-control" id="mobile" name="mobile"
                                                       value="{{isset($user->mobile)?$user->mobile:''}}"
                                                       placeholder="请如实填写">
                                            </div>
                                        </div>
                                        <div class="col-xs-12 col-md-6">
                                            <label class="label-intro" for="mobile"></label>
                                        </div>
                                    </div>

                                    <div class="row input-row">
                                        <label class="col-xs-12 title" for="exampleInputPassword1">
                                            收款账户 - Accounts Receivable
                                        </label>
                                        <div class="col-md-4 col-xs-12">
                                            <div class="input-group">
                                                    <span class="input-group-addon">
                                                        <i class="iconfont icon-bixuan-copy font-red"></i>
                                                    </span>
                                                <input type="text" class="form-control" id="receipt" name="receipt"
                                                       value="{{isset($user->receipt)?$user->receipt:''}}"
                                                       placeholder="请如实填写">
                                            </div>
                                        </div>
                                        <div class="col-xs-12 col-md-6">
                                            <label class="label-intro" for="receipt"></label>
                                        </div>
                                    </div>

                                    <div class="row input-row">
                                        <div class="col-xs-12">
                                            <button type="submit" class="btn blue-madison">
                                                <i class="iconfont icon-duihao"></i>&nbsp;立即保存
                                            </button>
                                        </div>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('footer')
    <script type="text/javascript">
        $("#myInfo").validate({
            rules: {
                email: {
                    required: true,
                    maxlength: 100
                },
                realname: {
                    required: true,
                    maxlength: 5
                },
                mobile: {
                    required: true,
                    maxlength: 20
                },
                receipt: {
                    required: true,
                    maxlength: 50
                }
            }, errorPlacement: function (error, element) {
                $(element).closest("form").find("label[for='" + element.attr("id") + "']").html(error);
            },
            submitHandler: function (form) {
                $(form).ajaxSubmit({
                    dataType: "json",
                    type: "post",
                    success: function (data) {
                        if (data.code == 0) {
                            toastr["success"](data.msg);
                            setInterval(function () {
                                window.location = "{{route('sys.information')}}";
                            }, 2000);
                        } else {
                            toastr["error"](data.msg);
                        }
                    }
                });
            }
        });
    </script>
@endsection